from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-01-06 14:04:17.227813
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 06, Jan, 2022
Time: 14:04:22
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.6274
Nobs: 528.000 HQIC: -48.0702
Log likelihood: 6112.93 FPE: 9.99287e-22
AIC: -48.3550 Det(Omega_mle): 8.44024e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.394513 0.074406 5.302 0.000
L1.Burgenland 0.102383 0.043104 2.375 0.018
L1.Kärnten -0.113319 0.022213 -5.101 0.000
L1.Niederösterreich 0.175289 0.089703 1.954 0.051
L1.Oberösterreich 0.106844 0.089484 1.194 0.232
L1.Salzburg 0.269834 0.045534 5.926 0.000
L1.Steiermark 0.029830 0.059943 0.498 0.619
L1.Tirol 0.109937 0.048285 2.277 0.023
L1.Vorarlberg -0.077233 0.042719 -1.808 0.071
L1.Wien 0.007789 0.079134 0.098 0.922
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.050661 0.163509 0.310 0.757
L1.Burgenland -0.041770 0.094721 -0.441 0.659
L1.Kärnten 0.040104 0.048813 0.822 0.411
L1.Niederösterreich -0.210490 0.197125 -1.068 0.286
L1.Oberösterreich 0.459833 0.196643 2.338 0.019
L1.Salzburg 0.289830 0.100063 2.896 0.004
L1.Steiermark 0.116169 0.131727 0.882 0.378
L1.Tirol 0.306885 0.106108 2.892 0.004
L1.Vorarlberg 0.018625 0.093875 0.198 0.843
L1.Wien -0.020614 0.173898 -0.119 0.906
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.206833 0.038015 5.441 0.000
L1.Burgenland 0.092921 0.022022 4.219 0.000
L1.Kärnten -0.007373 0.011349 -0.650 0.516
L1.Niederösterreich 0.231375 0.045830 5.049 0.000
L1.Oberösterreich 0.160814 0.045718 3.518 0.000
L1.Salzburg 0.041350 0.023264 1.777 0.075
L1.Steiermark 0.025542 0.030625 0.834 0.404
L1.Tirol 0.083492 0.024669 3.384 0.001
L1.Vorarlberg 0.054407 0.021825 2.493 0.013
L1.Wien 0.112005 0.040430 2.770 0.006
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.136410 0.038027 3.587 0.000
L1.Burgenland 0.039661 0.022029 1.800 0.072
L1.Kärnten -0.014688 0.011352 -1.294 0.196
L1.Niederösterreich 0.164588 0.045845 3.590 0.000
L1.Oberösterreich 0.333706 0.045733 7.297 0.000
L1.Salzburg 0.106614 0.023271 4.581 0.000
L1.Steiermark 0.108455 0.030636 3.540 0.000
L1.Tirol 0.093475 0.024677 3.788 0.000
L1.Vorarlberg 0.053555 0.021832 2.453 0.014
L1.Wien -0.022508 0.040443 -0.557 0.578
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.094937 0.072303 1.313 0.189
L1.Burgenland -0.042156 0.041885 -1.006 0.314
L1.Kärnten -0.045907 0.021585 -2.127 0.033
L1.Niederösterreich 0.147788 0.087167 1.695 0.090
L1.Oberösterreich 0.177117 0.086954 2.037 0.042
L1.Salzburg 0.280883 0.044247 6.348 0.000
L1.Steiermark 0.062205 0.058249 1.068 0.286
L1.Tirol 0.154514 0.046920 3.293 0.001
L1.Vorarlberg 0.093106 0.041511 2.243 0.025
L1.Wien 0.081626 0.076896 1.062 0.288
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.090296 0.056026 1.612 0.107
L1.Burgenland 0.018585 0.032456 0.573 0.567
L1.Kärnten 0.052087 0.016726 3.114 0.002
L1.Niederösterreich 0.184940 0.067544 2.738 0.006
L1.Oberösterreich 0.328813 0.067379 4.880 0.000
L1.Salzburg 0.042886 0.034286 1.251 0.211
L1.Steiermark -0.002405 0.045136 -0.053 0.958
L1.Tirol 0.126131 0.036358 3.469 0.001
L1.Vorarlberg 0.062406 0.032166 1.940 0.052
L1.Wien 0.097393 0.059586 1.635 0.102
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.163560 0.068172 2.399 0.016
L1.Burgenland 0.012599 0.039492 0.319 0.750
L1.Kärnten -0.065046 0.020352 -3.196 0.001
L1.Niederösterreich -0.106385 0.082187 -1.294 0.196
L1.Oberösterreich 0.221721 0.081986 2.704 0.007
L1.Salzburg 0.046061 0.041719 1.104 0.270
L1.Steiermark 0.253744 0.054920 4.620 0.000
L1.Tirol 0.498600 0.044239 11.271 0.000
L1.Vorarlberg 0.065910 0.039139 1.684 0.092
L1.Wien -0.086785 0.072503 -1.197 0.231
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.163063 0.075239 2.167 0.030
L1.Burgenland -0.006630 0.043586 -0.152 0.879
L1.Kärnten 0.063972 0.022462 2.848 0.004
L1.Niederösterreich 0.176028 0.090708 1.941 0.052
L1.Oberösterreich -0.068618 0.090486 -0.758 0.448
L1.Salzburg 0.208811 0.046044 4.535 0.000
L1.Steiermark 0.139712 0.060614 2.305 0.021
L1.Tirol 0.054464 0.048826 1.115 0.265
L1.Vorarlberg 0.145153 0.043197 3.360 0.001
L1.Wien 0.126810 0.080019 1.585 0.113
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.425242 0.043722 9.726 0.000
L1.Burgenland -0.004766 0.025328 -0.188 0.851
L1.Kärnten -0.020759 0.013053 -1.590 0.112
L1.Niederösterreich 0.193797 0.052711 3.677 0.000
L1.Oberösterreich 0.234248 0.052582 4.455 0.000
L1.Salzburg 0.038216 0.026757 1.428 0.153
L1.Steiermark -0.020685 0.035224 -0.587 0.557
L1.Tirol 0.090411 0.028373 3.186 0.001
L1.Vorarlberg 0.047743 0.025102 1.902 0.057
L1.Wien 0.019733 0.046500 0.424 0.671
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.030603 0.089629 0.155823 0.135648 0.074666 0.079489 0.019272 0.200589
Kärnten 0.030603 1.000000 -0.030926 0.131206 0.045777 0.079668 0.446690 -0.074408 0.091889
Niederösterreich 0.089629 -0.030926 1.000000 0.303373 0.124547 0.258101 0.060520 0.148701 0.271399
Oberösterreich 0.155823 0.131206 0.303373 1.000000 0.214952 0.287135 0.165060 0.129103 0.220988
Salzburg 0.135648 0.045777 0.124547 0.214952 1.000000 0.121727 0.078584 0.107163 0.125255
Steiermark 0.074666 0.079668 0.258101 0.287135 0.121727 1.000000 0.130356 0.095222 0.015742
Tirol 0.079489 0.446690 0.060520 0.165060 0.078584 0.130356 1.000000 0.061491 0.145844
Vorarlberg 0.019272 -0.074408 0.148701 0.129103 0.107163 0.095222 0.061491 1.000000 -0.013005
Wien 0.200589 0.091889 0.271399 0.220988 0.125255 0.015742 0.145844 -0.013005 1.000000